/**
 * Creates Handlers for UI and IO. 
 * Acts as centralised start and end point for program.
 */

package manager;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import ui.AgentCreationScreen;
import ui.IdleScreen;

import java.util.Vector;


public class AgentManagerMIDlet extends MIDlet{
	private Display display;
	private UIHandlerManager uiHandler;
	private IOHandlerManager ioHandler;
	
		public AgentManagerMIDlet(){
			display = Display.getDisplay(this);
		//	uiHandler.start();
		}
		
		/*Called upon instanciation */
		public void startApp()
		{
			try{
				uiHandler = new UIHandlerManager(this,display);
				uiHandler.run();
			}catch(Exception e){
				e.printStackTrace();
			}
//	        Displayable current = Display.getDisplay(this).getCurrent();
//	        if(current == null)
//	        {
//	            ui.AgentCreationScreen creationScreen = 
//	            	new ui.AgentCreationScreen(this, "Please Select an Agent to create",display);
//	            display.setCurrent(creationScreen);
//	        }
	    }
		
		public void createIOHandlerManager(String address){
			this.ioHandler = new IOHandlerManager(this,address);
			this.ioHandler.run();
		}
		
		public IOHandlerManager getIOHandlerManager(){
			return this.ioHandler;
		}
		
		public UIHandlerManager getUIHandlerManager(){
			return this.uiHandler;
		}
		
		/* On pause */
	    public void pauseApp()
	    {
	    }

	    /*On destruction */
	    public void destroyApp(boolean b)
	    {
	    }


	    // A convenience method for exiting
	    public void exitRequested()
	    {
	        destroyApp(false);
	        notifyDestroyed();
	    }
}
